from ygframe.db.column import Column
from ygframe.mongo_wrapper.mongo_model import AbstractMongoModel


class ResourceType:
    MYSQL = 'mysql'
    REDIS = 'redis'


class Status:
    RECEIVED = 'received'
    RUNNING = 'running'
    RELEASED = 'released'


class ResourceInfo(AbstractMongoModel):
    resource_id = Column(unique=True)
    resource_name = Column()
    user_id = Column()
    resource_type = Column(one_of=ResourceType)
    image = Column()
    container_port = Column(int)
    host_ip = Column()
    host_port = Column(int)
    access_info = Column(dict)
    env = Column(dict)
    cmd = Column(list)
    args = Column(list)
    limits = Column(dict)
    requests = Column(dict)
    apply_date = Column(description='yyyy-MM-DD')

    status = Column(one_of=Status, default=Status.RECEIVED)

    def __init__(
            self,
            resource_id: str = None,
            user_id: str = None,
            env: dict = None,
            cmd: list = None,
            requests: dict = None,
            container_port: int = None,
            status: str = 'received',
            resource_type: str = None,
            apply_date: str = None,
            access_info: dict = None,
            host_port: int = None,
            limits: dict = None,
            image: str = None,
            host_ip: str = None,
            resource_name: str = None,
            args: list = None
    ) -> None:
        object.__init__(self)
        self.resource_id = resource_id
        self.user_id = user_id
        self.env = env
        self.cmd = cmd
        self.requests = requests
        self.container_port = container_port
        self.status = status
        self.resource_type = resource_type
        self.apply_date = apply_date
        self.access_info = access_info
        self.host_port = host_port
        self.limits = limits
        self.image = image
        self.host_ip = host_ip
        self.resource_name = resource_name
        self.args = args
        self.after_init()


if __name__ == '__main__':
    ResourceInfo.regenerate_init_method()
